
package code.codeworld.know.knowledge.controller;


import code.codeworld.know.knowledge.model.Know;
import code.codeworld.know.knowledge.model.vo.KnowVo;
import code.codeworld.know.knowledge.service.KnowService;
import code.codeworld.common.kits.Exceptions;
import code.codeworld.common.kits.Request;
import code.codeworld.common.kits.Result;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.util.ObjectUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.math.BigInteger;
import java.util.List;

/**
 * know控制器
 *
 * @author freecode
 * @date 2023/03/23 00:20
 */
@CrossOrigin
@RequestMapping(Request.CODEWORLD_WEB)
@RestController
@Validated
public class KnowCtl {

    @Resource
    private KnowService knowService;

    /**
     * 获取know分页
     *
     * @author freecode
     * @date 2023/03/23 00:20
     */
    @GetMapping("knowledge/page")
    public Page<KnowVo> page(KnowVo knowVo) {
        if (ObjectUtils.isEmpty(knowVo.getType())) {
            throw new Exceptions(Exceptions.ErrorCode.BAD_REQUEST);
        }
        return knowService.page(knowVo);
    }

    /**
     * 获取know集合
     *
     * @author freecode
     * @date 2023/10/15 00:20
     */
    @GetMapping("knowledge/list")
    public List<KnowVo> list(KnowVo knowVo) {
        if (ObjectUtils.isEmpty(knowVo.getType())) {
            throw new Exceptions(Exceptions.ErrorCode.BAD_REQUEST);
        }
        return knowService.list(knowVo);
    }

    /**
     * 获取know详情
     *
     * @author freecode
     * @date 2023/03/23 00:20
     */
    @GetMapping("knowledge/detail")
    public Result<Know> detail(@Valid Know know) {
        return Result.data(knowService.detail(know));
    }

    /**
     * 编辑know
     *
     * @author freecode
     * @date 2023/03/23 00:20
     */
    @PostMapping("knowledge/editMark")
    public Result<String> editMark(@RequestBody @Valid Know know) {
        return knowService.editMark(know);
    }

}
